<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    input {
      margin: 5px 5px;
    }
    ul {
      list-style: none;
    }
  </style>
  <body>
    <h2>省市区查询</h2>
    请输入省份：<input type="text" name="province" placeholder="浙江省" /><br />
    请输入城市：<input type="text" name="city" placeholder="杭州市" />
    <br /><button>查询</button>
    <ul class="list"></ul>
    <script src="./axios.js"></script>
    <script>
      const but = document.querySelector('button')
      const province = document.querySelector('input[name=province]')
      const city = document.querySelector('input[name=city]')
      const ul = document.querySelector('ul')
      but.addEventListener('click', async function () {
        const pname = province.value
        const cname = city.value
        const print = await axios({
          url: 'http://ajax-api.itheima.net/api/area',
          method: 'GET',
          params: { pname, cname },
        })
        const {
          data: { data },
        } = print
        ul.innerHTML = data
          .map((item) => {
            return `<li>${item}</li>`
          })
          .join('')
      })
    </script>
  </body>
</html>
